﻿using BLL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WeChat.Common;

namespace WeChat.UserInfo
{
    public partial class UpdatePassword : System.Web.UI.Page
    {
        public string rfkh;
        GetUserInfoBLL gb = new GetUserInfoBLL();
        protected void Page_Load(object sender, EventArgs e)
        {

            if (Request.QueryString["code"] != null || Request.QueryString["code"] != "")
            {
                string code = Request.QueryString["code"];
                //ApplicationLog.Write("充值记录code:" + code);
                if (Session["openid"] == null || Session["openid"].ToString() == "")
                {
                    Session["openid"] = OAuthHelper.getOpenid(code);
                }
                string openid = Session["openid"].ToString();
                //string openid = "opc0cwB3k-hFwKzwRZ68dp-qIrqs";
                if (!new BindIdBLL().verifyId(openid))//验证是否绑定账号
                {
                    Response.Redirect("/WeChat/Binding.aspx?openid=" + openid);
                }
                else
                {

                    DataTable dt = gb.getUserInfo(openid).Tables[0];
                    rfkh = dt.Rows[0]["rfkh"].ToString();
                }
            }
        }

        protected void bt1_Click(object sender, EventArgs e)
        {
            string cardid = Request["cardid"].ToString();
            string ypassword = Request["ypassword"].ToString();
            string xpassword = Request["xpassword"].ToString();
            string qpassword = Request["qpassword"].ToString();
            DataTable dt = gb.getypassword(cardid).Tables[0];
            string password = dt.Rows[0]["password"].ToString();
            if (ypassword != password)
            {
                notice.InnerText = "原始密码输入错误";
                return;
            }
            else
            {
                if (xpassword == "" && qpassword == "") { return; }
                if (xpassword != qpassword && xpassword != "" && qpassword != "")
                {
                    notice.InnerText = " '新密码' 和 '再次输入新密码' 不一致，请核对！";
                    return;
                }
                else
                {
                    int a = gb.Pwdchange(cardid, qpassword);
                    if (a > 0)
                    {
                        Response.Cookies["ddls"].Expires = DateTime.Now.AddDays(-1);
                        Response.Cookies["Name"].Expires = DateTime.Now.AddDays(-1);
                        Response.Cookies["PassWord"].Expires = DateTime.Now.AddDays(-1);
                        panel1.Visible = false;
                        success.Visible = true;
                    }
                }
            }
        }
    }
}